﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Harvest.Api.Model;

namespace Harvest.WinForms
{

    public partial class ClientForm : Form
    {

        public Client Client = null;

        public ClientForm(Client client)
        {
            Client = client;
            InitializeComponent();

            this.Load += new EventHandler(ClientForm_Load);
            okButton.Click += new EventHandler(okButton_Click);
        }


        void okButton_Click(object sender, EventArgs e)
        {
            if (Client == null) Client = new Client();
            //Client.Name = nameTextBox.Text;
            //Client.Details = detailsTextBox.Text;
            //Client.Currency = currencyTextBox.Text;
            Client.Id = idTextBox.Text == "" ? (int?) null : int.Parse(idTextBox.Text);
            Client.Active = activeCheckBox.Checked;
            Client.Name = nameTextBox.Text;
            Client.Details = detailsTextBox.Text;
            //updatedTextBox.Text = Client.UpdatedAt.ToString();
            //createdTextBox.Text = Client.CreatedAt.ToString();
            //invoiceTextBox.Text = Client.DefaultInvoiceTimeframe;
            //highriseTextBox.Text = Client.HighriseId.ToString();
            Client.CurrencySymbol = symbolTextBox.Text;
            Client.Currency = currencyTextBox.Text;
            //versionTextBox.Text = Client.CacheVersion;
        }


        void ClientForm_Load(object sender, EventArgs e)
        {
            if (Client != null)
            {
                idTextBox.Text = Client.Id.ToString();
                activeCheckBox.Checked = Client.Active;
                nameTextBox.Text = Client.Name;
                detailsTextBox.Text = Client.Details;
                updatedTextBox.Text = Client.UpdatedAt.ToString();
                createdTextBox.Text = Client.CreatedAt.ToString();
                invoiceTextBox.Text = Client.DefaultInvoiceTimeframe;
                highriseTextBox.Text = Client.HighriseId.ToString();
                symbolTextBox.Text = Client.CurrencySymbol;
                currencyTextBox.Text = Client.Currency;
                versionTextBox.Text = Client.CacheVersion;
            }
        }

    }

}
